(function () {

	$(function () {
		packager('app.components.sidebar');

		app.components.sidebar = new function () {

			var exports = {};

			exports.init = function () {

				exports.actions.initSidebar();
			};

			exports.actions = {};

			exports.actions.initSidebar = initSidebar;

			return exports;
		};
	});

	function initSidebar() {
		// mark the current tab
		$list = $('.page-sidebar-menu');
		$list.find('li').each(function () {
			// add a slash to exclude similar pathname
			if ((location.pathname + '/').indexOf($(this).find('a').attr('href') + '/') !== -1) {
				$list.find('li').removeClass('active');
				$(this).addClass('active');
				Cookies.set('nav_pathname', $(this).children('a').first().attr('href'), {path: '/'});
			}
		});

		// click event
		$list.on('click', 'li:not(.heading)', function () {
			$list.find('li').removeClass('active');
			$(this).addClass('active');
			Cookies.set('nav_pathname', $(this).children('a').first().attr('href'), {path: '/'});
		});
	}

})();